package testsuite;

import snobject.snString;
import step.ExpNode;
import step.Graph;
import step.ValueNode;
import sxe.GraphEvaluatorThread;

/*
 Created on Jun 22, 2005
 (C) 2005 
 @author Michael Long

 This program is free software; you can redistribute it and/or
 modify it under the terms of Version 2 of the GNU General Public 
 License.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; if not, write to the Free
 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

public class tester {

	Graph XE_Graph;
	static GraphEvaluatorThread eval;
	
	public void soSXE(String sID){
		// need multiple threads -- evaluator:
		
		XE_Graph = Graph.newEmptyGraph(sID);
		
	}
	public static void main(String[] args) {
		eval = null;
		try{
			
			ExpNode exp = new ExpNode("framegrabber","sxe.core.video.grabframe");
			exp.AddChild(new ValueNode(new snString("1")));
			exp.AddChild(new ValueNode(new snString("320x240")));
			
			ExpNode exp2 = new ExpNode("timestamp","sxe.core.video.timestamp");
			exp2.AddChild(exp);
			
			
			Graph g = Graph.newEmptyGraph("framegrabber_320");
			exp2.Realize(g);
			g.Write("framegrabber_320.step.xml");
			// trigger tests 		
			/*
			ExpNode exp2 = new ExpNode("rand","sxe.core.math.random");
			exp2.AddChild(new ValueNode(new snInteger(0)));
			exp2.AddChild(new ValueNode(new snInteger(5)));
			
			ExpNode expTest = new ExpNode("equals","sxe.core.equals");
			expTest.AddChild(new ValueNode(new snInteger(4)));
			expTest.AddChild(exp2);

			ExpNode exp = new ExpNode("add","sxe.core.math.add");
			exp.AddChild(new ValueNode(new snInteger(2)));
			exp.AddChild(new ValueNode(new snInteger(8)));
			
			TriggerNode tn = new TriggerNode("TriggerHead");
			tn.AddChild(expTest);
			tn.AddChild(exp);
			*/
			
			// MATH tests 
			/*
			ExpNode exp = new ExpNode("add","sxe.core.math.add");
			exp.AddChild(new ValueNode(snObject.Integer(2)));
			exp.AddChild(new ValueNode(snObject.Integer(8)));
			
			ExpNode exp2 = new ExpNode("sub","sxe.core.math.subtract");
			exp2.AddChild(exp);
			exp2.AddChild(new ValueNode(snObject.Integer(3)));
			
			ExpNode exp3 = new ExpNode("equals","sxe.core.equals");
			exp3.AddChild(new ValueNode(snObject.Integer(7)));
			exp3.AddChild(exp2);
			
			
			// STRING tests
			
			ExpNode expA = new ExpNode("cat","sxe.core.string.concat");
			expA.AddChild(new ValueNode(snObject.String("Hell")));
			expA.AddChild(new ValueNode(snObject.String("o Wo")));
			expA.AddChild(new ValueNode(snObject.String("rld")));
			expA.AddChild(new ValueNode(snObject.String("!")));
			
			ExpNode expB = new ExpNode("substr","sxe.core.string.substring");
			expB.AddChild(expA);
			expB.AddChild(new ValueNode(snObject.Integer(2)));
			expB.AddChild(new ValueNode(snObject.Integer(7)));
			*/
			
			/* FRAMEGRABBER tests */
			
			//ExpNode exp1 = new ExpNode("grabber","sxe.core.video.grabframe");
			
			//ExpNode root = tn;
			//Graph g = Parser.Parse(new File("at.out")); 
			//g.Write("at.out");
			
			//Graph g = Graph.newEmptyGraph("id1");
			//exp1.Realize(g);
			//exp2.Realize(g);
			//exp.Realize(g);
			//expTest.Realize(g);
			//tn.Realize(g);
			//g.Write("trigger.out");
			
			
			/*
			 * 
			GraphEvaluatorThread eval = new GraphEvaluatorThread(g);
			eval.start();
			*/
			System.out.println("Waiting for user to let it end");
			System.in.read();
			
			//System.out.println(exp1.TryEvaluate());
			/*
			while(!root.IsEnabled())
				g.iterate();
			root.TryEvaluate();
			*/
			
			/*
			snObject sno = g.GetNode("substr").GET_value();
			System.out.println(sno.getContent());			
			sno = g.GetNode("equals").GET_value();
			System.out.println(sno.getContent());
			*/
			//eval.Shutdown();
			
//		}catch(EvaluationFailure ef){
//			System.out.println(ef.GetReason());
//			ef.printStackTrace(System.out);
		}
		catch(Exception e){
			System.out.println();
			e.printStackTrace(System.out);
			if(eval!=null)
				eval.Shutdown();
		}
	}
}
